﻿/* EntitiesToDTOs. Copyright (c) 2012. Fabian Fernandez.
 * http://entitiestodtos.codeplex.com
 * Licensed by Common Development and Distribution License (CDDL).
 * http://entitiestodtos.codeplex.com/license
 * Fabian Fernandez. 
 * http://www.linkedin.com/in/fabianfernandezb/en
 * */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EntitiesToDTOs.Domain;
using EntitiesToDTOs.Helpers;
using EntitiesToDTOs.Properties;

namespace EntitiesToDTOs.UI
{
    /// <summary>
    /// New update available window.
    /// </summary>
    internal partial class UpdateWindow : Form
    {
        /// <summary>
        /// New release available.
        /// </summary>
        private Release NewRelease { get; set; }



        /// <summary>
        /// Creates an instance of <see cref="UpdateWindow"/>.
        /// </summary>
        /// <param name="newRelease">New release available.</param>
        public UpdateWindow(Release newRelease)
        {
            InitializeComponent();

            this.NewRelease = newRelease;

            this.Text = Resources.Info_Caption;

            this.txtMessage.Text = string.Format(Resources.Info_NewRelease, this.NewRelease.Version);
        }



        /// <summary>
        /// Executed when the user clicks the learn more button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLearnMore_Click(object sender, EventArgs e)
        {
            try
            {
                // Navigate to release web page
                System.Diagnostics.Process.Start(this.NewRelease.Link);

                // Close window
                this.Close();
            }
            catch (Exception ex)
            {
                LogManager.LogError(ex);

                MessageHelper.ShowErrorMessage(ex.Message);
            }
        }

        /// <summary>
        /// Executed when the user clicks the remind me later button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRemindMeLater_Click(object sender, EventArgs e)
        {
            // Just close the window
            this.Close();
        }

        /// <summary>
        /// Executed when the user clicks the no thanks button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNoThanks_Click(object sender, EventArgs e)
        {
            try
            {
                // Skip the release
                UpdateHelper.SkipRelease(this.NewRelease.ReleaseID);

                // Close window
                this.Close();
            }
            catch (Exception ex)
            {
                LogManager.LogError(ex);

                MessageHelper.ShowErrorMessage(ex.Message);
            }
        }

    }
}